
// ***********************************************************************
// AUTO GENERATED CLASS - Do Not Modify this file, if needed modify .tt
// ***********************************************************************
// Assembly         : InnovaApp_DomainLayer
// Author           : LJO+01
// Created          : 05/07/2013 23:07:47
// ***********************************************************************
// <copyright file="N.A." company="Copyright © Innovacall 2011">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary>
// Domain layer  
// DomainClass
// </summary>
// ***********************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;


namespace InnovaApp.Layers.DomainLayer
{
    /// <summary>
    /// Class LayoutMenu
    /// </summary>
    [Serializable]
    public partial class LayoutMenu : _DomainLayer_Base
    {
        #region Primitive Properties
    	
        /// <summary>
        /// Gets or sets Id.
        /// </summary>
        /// <value>The Id.</value>
        public virtual int Id
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets FK_InnoApplication.
        /// </summary>
        /// <value>The FK_InnoApplication.</value>
        /// <remarks>
        /// Foregn key of LayoutMenu
        /// 
        /// </remarks>
        public virtual System.Guid FK_InnoApplication
        {
            get { return _fK_InnoApplication; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_InnoApplication != value)
                    {
                        if (InnoApplication != null && InnoApplication.Id != value)
                        {
                            InnoApplication = null;
                        }
                        _fK_InnoApplication = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private System.Guid _fK_InnoApplication;
    	
        /// <summary>
        /// Gets or sets FK_LayoutMenu.
        /// </summary>
        /// <value>The FK_LayoutMenu.</value>
        /// <remarks>
        /// Foregn key of LayoutMenu1
        /// 
        /// </remarks>
        public virtual Nullable<int> FK_LayoutMenu
        {
            get { return _fK_LayoutMenu; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_LayoutMenu != value)
                    {
                        if (LayoutMenu2 != null && LayoutMenu2.Id != value)
                        {
                            LayoutMenu2 = null;
                        }
                        _fK_LayoutMenu = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private Nullable<int> _fK_LayoutMenu;
    	
        /// <summary>
        /// Gets or sets Name.
        /// </summary>
        /// <value>The Name.</value>
        public virtual string Name
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets Controller.
        /// </summary>
        /// <value>The Controller.</value>
        public virtual string Controller
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets DefaultAction.
        /// </summary>
        /// <value>The DefaultAction.</value>
        public virtual string DefaultAction
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets SortIndex.
        /// </summary>
        /// <value>The SortIndex.</value>
        public virtual int SortIndex
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets DisplayMenuToPublicIfPrivate.
        /// </summary>
        /// <value>The DisplayMenuToPublicIfPrivate.</value>
        public virtual Nullable<bool> DisplayMenuToPublicIfPrivate
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets rowversion.
        /// </summary>
        /// <value>The rowversion.</value>
        public virtual byte[] rowversion
        {
            get;
            set;
        }

        #endregion
        #region Navigation Properties
        public virtual InnoApplication InnoApplication
        {
            get { return _innoApplication; }
            set
            {
                if (!ReferenceEquals(_innoApplication, value))
                {
                    var previousValue = _innoApplication;
                    _innoApplication = value;
                    FixupInnoApplication(previousValue);
                }
            }
        }
        private InnoApplication _innoApplication;
    
        /// <summary>
        /// Link LayoutMenu to all LayoutMenu_Translation
        /// </summary>
        public virtual ICollection<LayoutMenu_Translation> LayoutMenu_Translation
        {
            get
            {
                if (_layoutMenu_Translation == null)
                {
                    var newCollection = new FixupCollection<LayoutMenu_Translation>();
                    newCollection.CollectionChanged += FixupLayoutMenu_Translation;
                    _layoutMenu_Translation = newCollection;
                }
                return _layoutMenu_Translation;
            }
            set
            {
                if (!ReferenceEquals(_layoutMenu_Translation, value))
                {
                    var previousValue = _layoutMenu_Translation as FixupCollection<LayoutMenu_Translation>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupLayoutMenu_Translation;
                    }
                    _layoutMenu_Translation = value;
                    var newValue = value as FixupCollection<LayoutMenu_Translation>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupLayoutMenu_Translation;
                    }
                }
            }
        }
        private ICollection<LayoutMenu_Translation> _layoutMenu_Translation;
    
        /// <summary>
        /// Link LayoutMenu to all LayoutMenu1
        /// </summary>
        public virtual ICollection<LayoutMenu> LayoutMenu1
        {
            get
            {
                if (_layoutMenu1 == null)
                {
                    var newCollection = new FixupCollection<LayoutMenu>();
                    newCollection.CollectionChanged += FixupLayoutMenu1;
                    _layoutMenu1 = newCollection;
                }
                return _layoutMenu1;
            }
            set
            {
                if (!ReferenceEquals(_layoutMenu1, value))
                {
                    var previousValue = _layoutMenu1 as FixupCollection<LayoutMenu>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupLayoutMenu1;
                    }
                    _layoutMenu1 = value;
                    var newValue = value as FixupCollection<LayoutMenu>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupLayoutMenu1;
                    }
                }
            }
        }
        private ICollection<LayoutMenu> _layoutMenu1;
        public virtual LayoutMenu LayoutMenu2
        {
            get { return _layoutMenu2; }
            set
            {
                if (!ReferenceEquals(_layoutMenu2, value))
                {
                    var previousValue = _layoutMenu2;
                    _layoutMenu2 = value;
                    FixupLayoutMenu2(previousValue);
                }
            }
        }
        private LayoutMenu _layoutMenu2;

        #endregion
        #region Association Fixup
    
        private bool _settingFK = false;
    
        private void FixupInnoApplication(InnoApplication previousValue)
        {
            if (previousValue != null && previousValue.LayoutMenu.Contains(this))
            {
                previousValue.LayoutMenu.Remove(this);
            }
    
            if (InnoApplication != null)
            {
                if (!InnoApplication.LayoutMenu.Contains(this))
                {
                    InnoApplication.LayoutMenu.Add(this);
                }
                if (FK_InnoApplication != InnoApplication.Id)
                {
                    FK_InnoApplication = InnoApplication.Id;
                }
            }
        }
    
        private void FixupLayoutMenu2(LayoutMenu previousValue)
        {
            if (previousValue != null && previousValue.LayoutMenu1.Contains(this))
            {
                previousValue.LayoutMenu1.Remove(this);
            }
    
            if (LayoutMenu2 != null)
            {
                if (!LayoutMenu2.LayoutMenu1.Contains(this))
                {
                    LayoutMenu2.LayoutMenu1.Add(this);
                }
                if (FK_LayoutMenu != LayoutMenu2.Id)
                {
                    FK_LayoutMenu = LayoutMenu2.Id;
                }
            }
            else if (!_settingFK)
            {
                FK_LayoutMenu = null;
            }
        }
    
        private void FixupLayoutMenu_Translation(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (LayoutMenu_Translation item in e.NewItems)
                {
                    item.LayoutMenu = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (LayoutMenu_Translation item in e.OldItems)
                {
                    if (ReferenceEquals(item.LayoutMenu, this))
                    {
                        item.LayoutMenu = null;
                    }
                }
            }
        }
    
        private void FixupLayoutMenu1(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (LayoutMenu item in e.NewItems)
                {
                    item.LayoutMenu2 = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (LayoutMenu item in e.OldItems)
                {
                    if (ReferenceEquals(item.LayoutMenu2, this))
                    {
                        item.LayoutMenu2 = null;
                    }
                }
            }
        }

        #endregion
    }
}
